/**
 * 
 */
package uno.component;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JOptionPane;

import uno.net.UnoPlay;
import uno.net.UnoPlayer;
import uno.utilities.URNResolver;

/**
 * @author mattialambertini
 *
 */
public class PlusFourCard extends Card {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7488063715045450498L;

	/**
	 * @param width
	 * @param height
	 * @param value
	 * @param parent
	 */
	public PlusFourCard(int width, int height, CardValue value,
			HandOfCard parent) {
		super(width, height, value, parent);
		
	}
	

	/* (non-Javadoc)
	 * @see uno.component.Card#addCardListeners()
	 */
	@Override
	protected void addCardClickListeners() {
		
		
		addMouseListener(new MouseAdapter(){
			
			public void mouseClicked(MouseEvent e) {
				
				super.mouseClicked(e);
				Card tmpCard = (Card)e.getSource();
				
				HandOfCard hocParent = getParent(); 
				hocParent.removeCard(tmpCard);//rimuovo dalla mano del giocatore la carta
				hocParent.repaint();
				clickBehavior(hocParent, tmpCard);
				
			}
			
			/**
			 * Metodo in cui e' implementato il comportamento di questa carta quando 
			 * viene giocata.
			 * */
			private void clickBehavior(HandOfCard hocParent, Card playedCard){

				System.out.println("Aggiungo +4 carte al giocatore successivo");
				String args[] = {CardValue.YELLOW, CardValue.GREEN, CardValue.RED, CardValue.BLUE};

				//faccio apparire un pop-up per scegliere il colore 
				int choice = JOptionPane.showOptionDialog(null, "Choose color:", "Color Dialog", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, args, null);
				System.out.println(choice);
				UnoPlayer currentPlayer = hocParent.getOwner();

				UnoPlay play = null;
				int deckSize = currentPlayer.getDeck().getDeckSize();

				//creo la mossa da spedire agli altri giocatori
				switch(choice) {

				case 0: 
					play = new UnoPlay(currentPlayer.getGameStatus().getID() + 1, currentPlayer.getMyPlayerID(), URNResolver.cardToURN(playedCard), deckSize, CardValue.YELLOW, currentPlayer.getHandOfCard().getHOCSize());
					break;
				case 1: 
					play = new UnoPlay(currentPlayer.getGameStatus().getID() + 1, currentPlayer.getMyPlayerID(), URNResolver.cardToURN(playedCard), deckSize, CardValue.GREEN, currentPlayer.getHandOfCard().getHOCSize());
					break;
				case 2: 
					play = new UnoPlay(currentPlayer.getGameStatus().getID() + 1, currentPlayer.getMyPlayerID(), URNResolver.cardToURN(playedCard), deckSize, CardValue.RED, currentPlayer.getHandOfCard().getHOCSize());
					break;
				case 3: 
					play = new UnoPlay(currentPlayer.getGameStatus().getID() + 1, currentPlayer.getMyPlayerID(), URNResolver.cardToURN(playedCard), deckSize, CardValue.BLUE, currentPlayer.getHandOfCard().getHOCSize());
					

				}

				//passo la mossa al giocatore che l'ha giocata in modo tale che possa gestirla
				currentPlayer.updateStatus(play);
				
			}
		

		});
	}

}
